package com.addr.action;

import com.addr.entity.Addr;
import com.addr.services.AddrServices;
import com.opensymphony.xwork2.ActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller
@Scope("prototype")
public class AddrAction {
    private Addr addr;
    @Autowired
    private AddrServices addrServices = null;
    public String add(){
        boolean flag = addrServices.add(addr);
        if (flag)
            return "addsuccess";
        else
            return "adderror";
    }

    public String delete(){
        boolean flag = addrServices.delete(addr);
        if (flag)
            return "deletetrue";
        else
            return "deleteerror";
    }
    public String update(){
        boolean flag = addrServices.update(addr);
        if (flag)
            return "updatesuccess";
        else
            return "updateerror";
    }
    public String select(){
        List<Addr> addrList = addrServices.select(addr);
        if (addrList!=null) {
            ActionContext.getContext().getValueStack().set("addrList",addrList);
            return "selectsuccess";
        }
        else
            return "selecterror";
    }
    public String selectOne(){
        Addr addr1 = addrServices.selectOne(addr);
        if (addr1!=null) {
            ActionContext.getContext().getValueStack().set("addr",addr1);
            return "selectonesuccess";
        }
        else
            return "selectoneerror";
    }

}
